/*
*  Impp - Instant Messenger
*
*  Copyright (C) 2001-2003  Oliver Schneider
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#include "Main.h"
#include "core/Impp.h"
#include  <wx/socket.h>


#include "modules/StdImportExportModule/ImportExport.h"


//#include "packageview/PackageParser.h"

//#include "flash/FlashPlugin.h"

//BEGIN_EVENT_TABLE(MyFrame, wxFrame)
//  EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
//    EVT_MENU(Minimal_About, MyFrame::OnAbout)
//END_EVENT_TABLE()

#ifdef __WXGTK__
// teach how wxString use streams (operator<<)
std::ostream & operator<<(std::ostream & out, const wxString & str)
{
   out << str.mb_str(wxConvUTF8);
   return out;
}

#endif

IMPLEMENT_APP(Impp::MyApp)

namespace Impp {

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;

	wxImage::AddHandler( new wxJPEGHandler());
	wxImage::AddHandler( new wxPNGHandler());
	wxImage::AddHandler( new wxGIFHandler());
	wxImage::AddHandler( new wxICOHandler());


    //wxLog::AddTraceMask(wxT("DATABASE"));

    //wxLog::AddTraceMask(wxT("IMPP"));

	//wxLog::AddTraceMask(wxT("ACTION_MANAGER"));

	//wxLog::AddTraceMask(wxT("AVATAR"));

    //wxLog::AddTraceMask(wxT("OSCAR"));

    //wxLog::AddTraceMask(wxT("OSCAR_SERVER_CON"));
    //wxLog::AddTraceMask(wxT("OSCAR_PACKAGE"));
    //wxLog::AddTraceMask(wxT("BUDDYLIST"));
    //wxLog::AddTraceMask(wxT("TASKMANAGER"));
	//wxLog::AddTraceMask(wxT("AWAY"));
    //wxLog::AddTraceMask(wxT("OSCAR_PACKAGE_FINE"));
    //wxLog::AddTraceMask(wxT("OSCAR_PACKAGE_SSI"));
    //wxLog::AddTraceMask(wxT("OSCAR_PACKAGE_STATUS"));
    //wxLog::AddTraceMask(wxT("RATE"));


   // FlashPlugin* plugin = new FlashPlugin();

	//PackageParser parser;

    Impp* impp = Impp::exemplar();
    impp->init(pProfilDir);
    iBuddyList* bl = impp->getModuleManager()->getBuddyListModule();
    if(bl){
    	bl->getWindow()->Show(true);
    }else{
    	wxLogError(wxT("No Buddylist Module loaed!"));
    	impp->close();
    	return false;
    }

   //new wxLogWindow(impp->getBuddyList(), wxT("log"));

    return true;
}

int MyApp::OnExit()
{
	wxImage::CleanUpHandlers();
    return wxApp::OnExit();
}

void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
{
	wxApp::OnInitCmdLine(parser);
    parser.AddOption(wxT("p"), wxT("profildir"), wxT("the directory to use for the profil data"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
    // must refuse '/' as parameter starter or cannot use "/path" style paths
    parser.SetSwitchChars(wxT("-"));
}


bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
	parser.Found(wxT("p"),&pProfilDir);

    return wxApp::OnCmdLineParsed(parser);
}

}
